package com.thrd.taiexhibition.model;

import com.alibaba.fastjson.JSON;
import com.thrd.basicframework.http.OkHttpUtils;
import com.thrd.basicframework.http.callback.ThrdCallBack;
import com.thrd.taiexhibition.bean.BeanCityIndustry;
import com.thrd.taiexhibition.bean.BeanCityIndustryFocus;
import com.thrd.taiexhibition.callback.MvpCallback;
import com.thrd.taiexhibition.utils.Constant;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: ${唐杰}
 * @date: 2021/3/25
 */
public class CityFocusModel  {
    public static final String TAG="CityFocusModel";

    /**
     * 获取城市首页
     */
    public void getCityFocusData(long id,final MvpCallback<BeanCityIndustry> mvpCallback){
        OkHttpUtils.get().url(Constant.HTTP_CITY_FOCUS)
                .tag(TAG)
                .addParams("cityId",String.valueOf(id))
                .build().execute(new ThrdCallBack<BeanCityIndustry>() {

            @Override
            public void onFailed(String e, int code) {
                mvpCallback.onFailed(e,code);
            }

            @Override
            public void onResponse(BeanCityIndustry response, int id) {
                mvpCallback.onSuccess(response);
            }

            @Override
            public BeanCityIndustry onJson(String s) {
                BeanCityIndustry mBeanCityIndustry=  JSON.parseObject(s,BeanCityIndustry.class);
                List<List<BeanCityIndustryFocus>> listlist=new ArrayList<>();
                if(mBeanCityIndustry!=null){
                    List<BeanCityIndustryFocus> mBeanCityIndustryFocusList=  mBeanCityIndustry.getCityIndustryList();
                    if(mBeanCityIndustryFocusList!=null){
                        List<BeanCityIndustryFocus> industryList = null;
                        for (int i=0;i<mBeanCityIndustryFocusList.size();i++){
                            if(i%2==0){
                                industryList=new ArrayList<>();
                                listlist.add(industryList);
                            }

                            industryList.add(mBeanCityIndustryFocusList.get(i));
                        }
                        mBeanCityIndustry.setCityIndustryListList(listlist);
                    }
                }
                return mBeanCityIndustry;
            }


        });


    }
}
